Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix statement vs expr #62

Merged
merged 5 commits into from
May 18, 2020
Merged

Conversation

jakzale
Copy link
Collaborator

@jakzale jakzale commented Apr 3, 2020

Fixes #51, #54

Essentially we make [Statement f] as our program and the main parsing rule.

  • Fix Sign vs Sig naming issue,
  • add Statements f newtype for [Statement f]
  • add Program f newtype of Statements f as top-level node of AST.
  • duplicate necessary functions with
    • stmt prefix for statements, and
    • expr prefix for expressions.
  • update and clean up all the test cases.
  • add stack bench for testing the generators.

In addition we add the benchmark of quickcheck generators

@jakzale jakzale requested a review from effectfully April 3, 2020 14:52
test/Field/golden/forLoops.golden Outdated Show resolved Hide resolved
field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Raw/Core.hs Show resolved Hide resolved
field/TinyLang/Field/Raw/Core.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Rename.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Rename.hs Outdated Show resolved Hide resolved
@jakzale jakzale force-pushed the fix-statement-vs-expr branch 2 times, most recently from 1563033 to 286f878 Compare April 9, 2020 20:52
field/TinyLang/Field/Typed/Core.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Typed/Parser.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Rename.hs Show resolved Hide resolved
field/TinyLang/Field/Rename.hs Show resolved Hide resolved
field/TinyLang/Field/Rename.hs Show resolved Hide resolved
@jakzale
Copy link
Collaborator Author

jakzale commented Apr 15, 2020

@effectfully, I added a benchmark (stack bench) for testing the generators.

Does the following output looks good to you?

Requested runs:  1000
Requested size:  1000

Minimum depth = 0
Maximum depth = 15
Mean depth    = 3.168

Minimum number of nodes = 0
Maximum number of nodes = 1890
Mean number of nodes    = 565.964

@effectfully
Copy link
Owner

Does the following output looks good to you?

Yes. We'll need some more refined tool to output other interesting stats (how many adds, muls etc there are, how many variables the program has, how many of them are mentioned at least twice, how many comparisons are done on "negative integers", etc).

We'll also need to see if it makes the compiler tests slower, 'cause they are already quite slow.

But for now looks good.

@jakzale jakzale marked this pull request as ready for review April 21, 2020 21:04
@jakzale jakzale linked an issue Apr 21, 2020 that may be closed by this pull request
Copy link
Owner

@effectfully effectfully left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll review the generators stuff a bit later.

field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Raw/Core.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Rename.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Typed/Core.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Typed/Parser.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Typed/Parser.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Typed/TypeChecker.hs Outdated Show resolved Hide resolved
test/Field/Textual.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Outdated Show resolved Hide resolved
@jakzale
Copy link
Collaborator Author

jakzale commented Apr 24, 2020

There are some issues with ProgramWithEnv arbitrary instances:

        *** Failed! (after 4 tests and 1 shrink):
        evaluation of renamed program
        [Some 16,Some (UniConst Bool False),Some 1]
        differs from evaluation of original program
        [Some (UniConst Bool False),Some 16]
        for final state of renamed program
        Right (Env {unEnv = fromList [(0,Some 16),(9,Some (UniConst Bool False)),(23,Some 1)]})
        for final state of evaluated program
        Right (Env {unEnv = fromList [(9,Some (UniConst Bool False)),(23,Some 16)]})
        for renamed program
        let u_0 = 16;
        
        for original program
        let u_23 = 16;
        
        ProgramWithEnv (Program (Statements [ELet (UniVar {_uniVarUni = Field, _uniVarVar = u_23}) (EConst 16)])) (Env {unEnv = fromList [(9,Some (UniConst Bool False)),(23,Some 1)]})

field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Raw/Core.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Generator.hs Outdated Show resolved Hide resolved
test/Field/Textual.hs Outdated Show resolved Hide resolved
test/Field/Textual.hs Show resolved Hide resolved
field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
@jakzale jakzale force-pushed the fix-statement-vs-expr branch 2 times, most recently from 1895d10 to 8a10069 Compare May 14, 2020 12:02
Fixes effectfully#51, effectfully#52

We make the following changes to the AST by adding
- a newly introduced a top-level `Program` node, which is parent to
- a newly introduced `Statements` node, which is parent to
- a `Statement` node, which is chaned to be a parent of
- an `Expr` node.

We make the following changes to Statement by
- introduce a `EFor` node to the typed AST.

We update update the evaluator by
- providing an explicit transformer stack (`EvalT`),
- fixing the semantics for for loops, and
- switching to CPS both in evaluator and normaliser.

We also add minor improvements to the codebase by
- fixing `Sign` vs `Sig` naming issue,
- cleaning up some naming conventions, and
- providing `stack bench` benchmark for testing generators for the new
  AST.
@jakzale jakzale requested a review from kwxm May 15, 2020 19:47
field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Evaluator.hs Outdated Show resolved Hide resolved
field/TinyLang/Field/Evaluator.hs Show resolved Hide resolved
@jakzale
Copy link
Collaborator Author

jakzale commented May 18, 2020

I suspect there will be a test error, but it will be tied to #76 due to lack of assignments and proper typing environments.

Copy link
Owner

@effectfully effectfully left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's get this in!

where
go i fkont = withVar var (Some $ fromIntegral i) $
evalStatements body fkont
actualEnd = Some $ fromIntegral $ max start end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per previous discussion we already know in the otherwise clause that start > end and hence can do withVar var start kont there instead, but not a big deal.

@effectfully effectfully merged commit 7ade59b into effectfully:master May 18, 2020
@jakzale jakzale deleted the fix-statement-vs-expr branch May 19, 2020 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loops Fix Statement vs Expr
2 participants